//
//  GDStatusCell.swift
//  weibo
//
//  Created by user on 15/11/29.
//  Copyright © 2015年 user. All rights reserved.
//

import UIKit

class GDStatusCell: UITableViewCell {
    
    //微博模型
    var status: GDStatus?{
        didSet{
            //将模型赋值给顶部视图，顶部视图就可以显示内容
            topView.status = status
            
            //cell 微博内容
            contentLabel.text = status?.text
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        prepareUI()
    }
    
    private func prepareUI() {
        //添加子控件
        contentView.addSubview(topView)
        contentView.addSubview(contentLabel)
        contentView.addSubview(bottomView)
        
        //添加约束
        //顶部控件
        topView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: contentView, size: CGSize(width: UIScreen.mainScreen().bounds.width, height: 53))
        
        //微博内容
        contentLabel.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: topView, size: nil, offset: CGPoint(x: 8, y: 8))
        
        //宽度
        contentLabel.addConstraint(NSLayoutConstraint(item: contentLabel, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: UIScreen.mainScreen().bounds.width - 2 * 8))
        
        /// 底部视图.在contentLabel的左下
        bottomView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: contentLabel, size: CGSize(width: UIScreen.mainScreen().bounds.width, height: 44), offset: CGPoint(x: -8, y: 8))
        
//        cell的高度
        contentView.addConstraint(NSLayoutConstraint(item: contentView, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: bottomView, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 0))
        
    }
    
    
    
    //懒加载
    ///顶部视图
    private lazy var topView: GDStatusTopView = GDStatusTopView()
    
    ///微博文字内容
    private lazy var contentLabel: UILabel = {
        
        let label = UILabel(color: UIColor.darkGrayColor(), fontSize: 14)
        
        //设置换行
        label.numberOfLines = 0
        
        return label
    }()
    
    ///底部视图
    private lazy var bottomView: GDStatusBottomView = GDStatusBottomView()
    
    ///配图视图
    lazy var pictureView: GDPictureView = GDPictureView()
    
    
}
